﻿using AutoMapper;
using D.Medicalcare.Domain.Entities;
using D.Medicalcare.ErrorCode;
using D.Medicalcare.Infrastructure.Interfaces;
using D.Medicalcare.Read.API.Application.Command.FeedbackCommand;
using MediatR;

namespace D.Medicalcare.Read.API.Application.Handler.FeedbackHandler
{
    public class GetFeedbackHandler : IRequestHandler<GetFeedbackCommand, APIResult<List<IssueFeedback>>>
    {
        private readonly IBaseRepository<IssueFeedback> feedbackRepo;
        private readonly ILogger<GetFeedbackHandler> logger;
        private readonly IMapper mapper;

        public GetFeedbackHandler(IBaseRepository<IssueFeedback> feedbackRepo, ILogger<GetFeedbackHandler> logger, IMapper mapper)
        {
            this.feedbackRepo = feedbackRepo;
            this.logger = logger;
            this.mapper = mapper;
        }

        public Task<APIResult<List<IssueFeedback>>> Handle(GetFeedbackCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<IssueFeedback>> result = new APIResult<List<IssueFeedback>>();
            result.Code = APIEnum.Success;
            result.Msg = "查询成功";
            var model = feedbackRepo.GetAll();
            result.Data = model.ToList();
            return Task.FromResult(result);
        }
    }
}
